# -*- coding: utf-8 -*-
"""
Created on Wed Jul 31 16:30:32 2024

@author: xiaobojie

点沿曲线移动的动态图
"""


import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
 

def update_points(num):
    
    # 此句ipython运行错误，spyder运行无动态
    # point_ani.set_data(x[num],y[num])
    
    # 此句 运行ok，将单个点作为数组传递？
    point_ani.set_data([x[num]], [y[num]])
    return point_ani,
 
x=np.linspace(0,2*np.pi,100)
y=np.sin(x)
 
fig=plt.figure(tight_layout=True)
plt.plot(x,y)
point_ani,=plt.plot(x[0],y[0],'ro')
plt.grid(ls='--')
ani=animation.FuncAnimation(fig,update_points,np.arange(0,100),interval=100,blit=True)
plt.show()


